from PIL import ImageGrab, Image
import pyautogui as pyg
#import pytesseract
import cv2
 
# 设置tesseract-ocr安装路径
#pytesseract.pytesseract.tesseract_cmd = r'/usr/local/Cellar/tesseract/5.2.0/bin/tesseract'  # 根据实际路径修改
 
# 捕获屏幕
#screenshot = ImageGrab.grab(bbox=[100,160,250,300])
#screenshot.save("/Users/zwf/Downloads/test/a.png")
screenshot=Image.open("/Users/zwf/Downloads/test/失败.png")
#screenshot = pyg.screenshot()
#(x,y)=(200,310)
#(bx,by)=(x+200,y+100)
#screenshot = screenshot.crop(box=(x,y,bx,by))
#screenshot.save("/Users/zwf/Downloads/test/成功.png",quality=95)
# 使用Tesseract进行文字识别
text = pytesseract.image_to_string(screenshot, lang='chi_sim',config="--oem 1 --psm 6 ")
 
print(text)